import numpy as np

'''
Array的创建及访问
'''
def main():
    # 创建一维numpy
    list1 = [1, 2, 3, 4, 5]
    array1 = np.array(list1)

    print(array1)

    # 创建二维numpy
    list2 = [6, 7, 8, 9, 10]
    array2 = np.array([list1, list2])

    print(array2)

    # 几行几列
    # (2, 5)
    print(array2.shape)

    # 总共的个数
    # 10
    print(array2.size)

    # 数据类型
    # int32
    print(array2.dtype)

    # 其他的创建方式
    # [1 3 5 7 9]
    array3 = np.arange(1, 10, 2)
    print(array3)

    # 返回全0的矩阵
    # [0. 0. 0. 0. 0.]
    print(np.zeros(5))
    # [[0. 0. 0.]
    #  [0. 0. 0.]]
    print(np.zeros([2, 3]))


    # 单位矩阵
    '''
    [[1. 0. 0. 0. 0.]
     [0. 1. 0. 0. 0.]
     [0. 0. 1. 0. 0.]
     [0. 0. 0. 1. 0.]
     [0. 0. 0. 0. 1.]]
    '''
    print(np.eye(5))


    # 二维数组访问，两种方法
    # 2
    print(array2[0][1])
    print(array2[0, 1])

    # 取范围
    '''
    [[ 2  3  4  5]
     [ 7  8  9 10]]
    '''
    print(array2[:2, 1:])

if __name__ == '__main__':
    main()
